library(ggplot2)
library(ggthemes)
# Basic plot
<- ggplot(mpg, aes(x=displ, y=hwy, color=class)) +
p geom_point() +
labs(title="Default Theme")
p
ggplot2 Themes
Introduction
In this document, we will explore various themes and styles available in ggplot2.
Below are examples of applying different themes to your plot:
Theme Minimal
+ theme_minimal() +
p labs(title="Theme Minimal")
Theme Classic
+ theme_dark() +
p labs(title="Theme Dark")
Theme Economist
+ theme_economist() +
p labs(title="Theme Economist")
Theme Economist - White
+ theme_economist_white() +
p labs(title="Theme Economist - White")
Theme Excel
+ theme_excel() +
p labs(title="Theme Excel")
Theme Excel - New
+ theme_excel_new() +
p labs(title="Theme Excel - New")
Theme Highcharts
+ theme_hc() +
p labs(title="Theme Highcharts")
Theme Google Docs
+ theme_gdocs() +
p labs(title="Theme Google Docs")
Theme 538
+ theme_fivethirtyeight() +
p labs(title="Theme 538")
Theme Stata
+ theme_stata() +
p labs(title="Theme Stata")
Theme Wall Street Journal (WSJ)
+ theme_wsj() +
p labs(title="Theme Wall Street Journal")
Theme Pander
+ theme_pander() +
p labs(title="Theme Pander")
Custom Theme
<- theme(
custom_theme plot.title = element_text(size=14, face="bold", hjust=0.5),
axis.title = element_text(size=12, face="bold"),
axis.text = element_text(size=10),
panel.background = element_rect(fill="white"),
panel.grid.major = element_line(color="grey", size=0.5),
panel.grid.minor = element_line(color="lightgrey", size=0.25)
)
Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
ℹ Please use the `linewidth` argument instead.
+ custom_theme + labs(title="Custom Theme") p